home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- * *
- * the Mac version of the PCB Cad program written by Randy Nevin *
- * was ported by Carlos Bazzarella, University of Waterloo. *
- * *
- ********************************************************************/
-
-
- #define BASE_RES_ID 400
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
-
- #define LEAVE_WHERE_IT_IS FALSE
- #define NORMAL_UPDATES TRUE
-
- #define SLEEP 0L
- #define NIL_MOUSE_REGION 0L
- #define WNE_TRAP_NUM 0x60
- #define UNIMPL_TRAP_NUM 0x9F
- #define SUSPEND_RESUME_BIT 0x0001
- #define ACTIVATING 1
- #define RESUMING 1
-
- #define DRAG_THRESHOLD 30
- #define MIN_WINDOW_HEIGHT 50
- #define MIN_WINDOW_WIDTH 50
- #define SCROLL_BAR_PIXELS 16
-
-
- WindowPtr gPictWindow;
- Boolean gDone, gWNEImplemented;
- EventRecord gTheEvent;
- Rect gDragRect, gSizeRect;
-
- char HandleEvent();
-
-
- SetUpMacInt()
- {
- ToolBoxInit();
- WindowInit();
- SetUpDragRect();
- SetUpSizeRect();
- }
-
-
-
- ToolBoxInit()
- {
- InitGraf( &thePort );
- InitFonts();
- FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( NIL_POINTER );
- InitCursor();
- }
-
-
- WindowInit()
- {
- gPictWindow = GetNewWindow ( BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT);
- /*ShowWindow (gPictWindow);*/
-
- /*SelectWindow (gPictWindow);*/
- }
-
-
-
-
- SetUpDragRect()
- {
- gDragRect = screenBits.bounds;
- gDragRect.left += DRAG_THRESHOLD;
- gDragRect.right -= DRAG_THRESHOLD;
- gDragRect.bottom -= DRAG_THRESHOLD;
- }
-
-
- SetUpSizeRect()
- {
- gSizeRect.top = MIN_WINDOW_HEIGHT;
- gSizeRect.left = MIN_WINDOW_WIDTH;
-
- gSizeRect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
- gSizeRect.right = screenBits.bounds.right - screenBits.bounds.left;
- }
-
-
- char getKey()
- {
- char c;
-
- gDone = FALSE;
- gWNEImplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap ) !=
- NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ));
- while ( gDone == FALSE )
- {
- c = HandleEvent();
- }
- return c;
- }
-
-
- char HandleEvent()
- {
- if ( gWNEImplemented )
- WaitNextEvent ( everyEvent , &gTheEvent , SLEEP,
- NIL_MOUSE_REGION);
- else
- {
- SystemTask();
- GetNextEvent( everyEvent, &gTheEvent );
- }
-
- switch ( gTheEvent.what )
- {
- case mouseDown :
- HandleMouseDown();
- break;
- case keyDown :
- case autoKey :
- gDone = TRUE;
- return ( gTheEvent.message & charCodeMask );
- break;
- default :
- return (0);
- break;
- }
- }
-
- HandleMouseDown()
- {
- WindowPtr whichWindow;
- short int thePart;
- long windSize;
- GrafPtr oldPort;
-
- thePart = FindWindow ( gTheEvent.where, &whichWindow);
- switch ( thePart )
- {
- case inSysWindow :
- SystemClick ( &gTheEvent, whichWindow );
- break;
- case inDrag :
- DragWindow (whichWindow, gTheEvent.where, &gDragRect );
- break;
- case inContent :
- SelectWindow (whichWindow);
- break;
- case inGrow :
- windSize = GrowWindow ( whichWindow, gTheEvent.where,
- &gSizeRect );
- if ( windSize != 0 )
- {
- GetPort ( &oldPort);
- SetPort ( whichWindow );
- EraseRect ( &whichWindow->portRect );
- SizeWindow (whichWindow, LoWord( windSize),
- HiWord( windSize), NORMAL_UPDATES);
- InvalRect ( &whichWindow->portRect );
- SetPort ( oldPort );
- }
- break;
- case inGoAway :
- gDone = TRUE;
- break;
- case inZoomIn :
- case inZoomOut :
- if ( TrackBox (whichWindow, gTheEvent.where, thePart ))
- {
- GetPort (&oldPort );
- SetPort ( whichWindow );
- EraseRect (&whichWindow->portRect );
- ZoomWindow (whichWindow, thePart, LEAVE_WHERE_IT_IS );
- InvalRect (&whichWindow->portRect );
- SetPort (oldPort );
- }
- break;
- }
- }
-
-
- DrawGrid ( RectPtr )
- Rect *RectPtr;
- {
- int x,y;
-
- PenPat ( ltGray );
-
- for ( y = RectPtr->top; y <= RectPtr->bottom; y = y + 25 )
- {
- MoveTo ( RectPtr->left, y);
- LineTo ( RectPtr->right, y);
- }
-
- for ( x = RectPtr->left; x <= RectPtr->right; x = x + 23 )
- {
- MoveTo ( x, RectPtr->top );
- LineTo ( x, RectPtr->bottom );
- }
-
- PenPat ( black );
- }